pro plotlidartxt, files, output_filename= output_filename, range = range, use_log = use_log, title = title, colorbar_title = colorbar_title, elev_angle = elev_angle, max_points = max_points, colortable=colortable, colortable_file=colortable_file

	; dealing with args
    if(n_elements(files) eq 0) then files = dialog_pickfile(filter='*.txt',/multiple_files);
    if(n_elements(output_filename) eq 0) then output_filename = 'idl.ps'
    if(n_elements(range) eq 0) then range = [0.0, 1.0]
	if(n_elements(title) eq 0) then title = ''
	if(n_elements(colorbar_title) eq 0) then colorbar_title = ''
	if(n_elements(elev_angle) eq 0) then elev_angle = 90.0
	if(n_elements(colortable) eq 0) then colortable = 13

	; read the data
    data = readlidartxt(files);

	; dealing with max_points
	if(n_elements(max_points) eq 1) then begin
		if( data.line_size gt max_points ) then begin
			data.line_size = max_points
			data.data = data.data[*, 0:max_points-1]
		endif
	endif
	line_size = data.line_size;

	; get ps ready
    ps_start, filename=output_filename,/inches, xsize=10, ysize=6
	if(n_elements(colortable_file) eq 0) then begin
	    ctload, colortable, ncolors=128
	endif else begin
		ctload, colortable, file=colortable_file, ncolors=128
	endelse
    colornames=load_coyote_colors()
    
    position = [0.07,0.15, 0.85, 0.9]
    
	; get time labels ready
    dummy = label_date(date_format=['%H:%I','%M %D, %Y'] )
    start_j = min(data.julian)
	end_j = max(data.julian)
	hours = (end_j - start_j) / $
		( julday(1, 1, 2000, 1, 0, 0) - julday(1, 1, 2000, 0, 0, 0) )
	; automaticly decide time label interval
	x_interval = 6
	if(hours ge 72) then x_interval = 12
	if(hours ge 144) then x_interval = 24
	if(hours le 6) then x_interval = 1
	if(hours le 3) then x_interval = 0.5
	if(hours le 1) then x_interval = 0.166666
	if(hours le 0.2) then x_interval = 0.0166666

	; get data logged
	if(n_elements(use_log) ne 0) then begin
		data.data = alog10(data.data);
	endif 
	; try automaticly decide range, but works badly
	if(n_elements(range) eq 0) then begin
		if Keyword_Set(use_log) then begin
			range = [max(data.data) - 4, max(data.data)]
		endif else begin
			range = [min(data.data), max(data.data)]
		endelse
	endif

	; get image scaled and plotted
	image=bytscl(data.data, top=127, min = range[0], max = range[1]);
    tvimage, image, position = position

    plot, /nodata,  data.julian, indgen(n_elements(data.julian)), $
		yrange = [0, (data.line_size -1)*data.binsize*sin(!pi*elev_angle/180.0)] , $
		position=position, xstyle=1 + 8, ystyle=1, $
		charsize = 1.0 , title = title, ytitle = 'km', $
		XTICKFORMAT=['LABEL_DATE', 'LABEL_DATE'], xtickunits=['Time','Day'], $
		xtickinterval = x_interval, xticklen=-0.02, yticklen = -0.01, $ 
		color = colornames.black, /noerase
    
	; colorbar stuff
	cb_div = 5
	cb_labels = findgen(cb_div+1) / cb_div * (range[1] - range[0]) + range[0]
	if( n_elements(use_log) ne 0) then begin
		cb_labels = 10.0 ^ cb_labels
		cb_lable_names = strtrim(string(cb_labels, format = '(%"%10.2e")'));
	endif else begin
		cb_lable_names = strtrim(string(cb_labels, format = '(%"%5.3f")'));
	endelse

    colorbar, position=[0.88, 0.15, 0.90, 0.9], /vertical, /right, ncolors=128, divisions = cb_div, ticknames = cb_lable_names, charsize = 1.0, color = colornames.black
	xyouts, 0.88, 0.1, colorbar_title, /normal, charsize=1.0, color = colornames.black
    
    ps_end, /png, /allow_transparent
    
    
end
